package demo.inoutput;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class IOSerialization {
	public static void main(String[] args) {
		Car c = new Car("Nissan", 1500, "blue");
		System.out.println("before: " + c.make + " " + c.weight);
		try {
			FileOutputStream fs = new FileOutputStream("C:/Users/TayDo/Demo/Car.txt");
			ObjectOutputStream os = new ObjectOutputStream(fs);
			os.writeObject(c);
			os.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		try {
			FileInputStream fis = new FileInputStream("C:/Users/TayDo/Demo/Car.txt");
			ObjectInputStream ois = new ObjectInputStream(fis);
			c = (Car) ois.readObject();
			ois.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("after: " + c.make + " " + c.weight);
	}
}


class NonLiving {
}

class Vehicle extends NonLiving {
	String make = "Lexus";
	String color = "Brown";
}

class Car extends Vehicle implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	protected int weight = 1000;

	Car(String n, int w, String c) {
		color = c;
		make = n;
		weight = w;
	}
}